package com.momo.encoderHandler3;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;

import java.util.List;

/**
 * @author Kagome
 * @title: MyPersionDecoder
 * @projectName boot2.X-netty
 * @description: 解码器
 * @date 2019/6/2 16:04
 */
public class MyPersionDecoder extends ReplayingDecoder<Void> {
    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        System.out.println("MyPersionDecoder 进入:");
        int length = in.readInt();
        byte[] content = new byte[length];
        in.readBytes(content);
        PersionProtocol persionProtocol=new PersionProtocol();
        persionProtocol.setLength(length);
        persionProtocol.setContent(content);
        out.add(persionProtocol);
    }
}
